# -*- coding: utf-8 -*-

import pickle
import socket

max_packet_size = 32*1024

def sendmsg(address, data, timeout=5):
    # Create a socket (SOCK_STREAM means a TCP socket)
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

    sock.settimeout(timeout)
    # Connect to server and send data
    sock.sendto( pickle.dumps(data, 2), address)

    received, address = sock.recvfrom(max_packet_size)

    sock.close()

    return pickle.loads( received )
